package com.yunxi.controller.approve;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.order.pojo.OrderReceiptVO;
import com.yunxi.order.service.OrderReceiptDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 发票表 前端控制器
 * </p>
 *
 * @author 
 * @since 2019-05-29
 */
@RestController
@RequestMapping("/wholesale/orderReceiptApprove")
@Api(tags = "wholesale:orderReceiptApprove", description = "发票表接口")
public class OrderReceiptApproveController {
     private static final Logger logger = LoggerFactory.getLogger(OrderReceiptApproveController.class);

     @Autowired
     OrderReceiptDubboService orderReceiptDubboService;

     @GetMapping("/page")
     @ApiOperation(value = "查询分页")
     public ApiResult page(@CurrentUser LoginInfo user,OrderReceiptVO orderReceiptVO, Integer pageNum, Integer pageSize) throws Exception {
         Object partnerVO = (Object) user.getPartner();
         if(partnerVO != null){
             //
             //表示当前用户是主机厂
             return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
         }
         return ResponseUtil.ok(orderReceiptDubboService.findPageByVO(orderReceiptVO,pageNum,pageSize));
     }

     @GetMapping("/load")
     @ApiOperation(value = "读取单个")
     public ApiResult load(String id, @CurrentUser LoginInfo loginInfo) throws Exception {
         return ResponseUtil.ok(orderReceiptDubboService.getById(id));
    }

     @PostMapping("/save")
     @ApiOperation(value = "保存信息")
     public ApiResult save(@RequestBody OrderReceiptVO orderReceiptVO,@CurrentUser LoginInfo loginInfo) throws Exception {
        orderReceiptDubboService.saveOrUpdate(orderReceiptVO);
        return ResponseUtil.ok("success");
    }

     @PostMapping("/del")
     @ApiOperation(value = "删除")
     public ApiResult del(@RequestBody List<OrderReceiptVO> orderReceiptVOList) throws Exception {
        orderReceiptDubboService.removeByListVo(orderReceiptVOList);
        return ResponseUtil.ok("success");
     }

    /*@PostMapping("/export")
    @ApiOperation(value = "导出excel")
    public Object export(@RequestParam Map<String,Object> params) throws Exception {
    return ResponseUtil.ok(orderReceiptDubboService.findMapByList(params));
    }*/
}
